﻿// Copyright (C) 2007 Blue Onion Software
// All rights reserved

using System;

namespace BlueOnionSoftware.Bloget
{
    public enum Mode
    {
        None,
        Blog,
        Post,
        Edit,
        Admin,
        Index,
        Drafts,
        LicenseAgreement,
        LogOn,
        LogOff,
        Log,
        Rss,
        Rpc,
        Search,
        Categories,
        Users,
        EditUser
    }

    static class Controller
    {
        internal static View Create(Bloget bloget, Mode mode)
        {
            switch (mode)
            {
                case Mode.LicenseAgreement:
                    return new LicenseView(bloget);

                case Mode.Blog:
                    return (bloget.QueryDate == DateTime.MinValue)
                               ? new BlogView(bloget)
                               : new PostsByMonthView(bloget);

                case Mode.Post:
                    return new PostView(bloget);

                case Mode.Edit:
                    return new EditView(bloget);

                case Mode.Admin:
                    return new AdminView(bloget);

                case Mode.Index:
                    return new IndexView(bloget);

                case Mode.Drafts:
                    return new DraftsView(bloget);

                case Mode.Log:
                    return new LogView(bloget);

                case Mode.LogOn:
                    return new PasswordView(bloget);

                case Mode.LogOff:
                    Log.Logout(bloget);
                    bloget.Page.Response.Clear();
                    System.Web.Security.FormsAuthentication.SignOut();
                    bloget.Redirect(bloget.BuildQueryString(Mode.Blog));
                    return new BlogView(bloget);

                case Mode.Rss:
                    return new RssView(bloget);

                case Mode.Rpc:
                    return new RpcView(bloget);

                case Mode.Search:
                    return new SearchView(bloget);

                case Mode.Categories:
                    return new CategoriesView(bloget);

                case Mode.Users:
                    return new UsersView(bloget);

                case Mode.EditUser:
                    return new EditUserView(bloget);

                default:
                    return new BlogView(bloget);
            }
        }
    }
}
